import os, sys
# base_dir=os.path.dirname(os.path.dirname(os.path.abspath(__file__)));
base_dir=os.path.abspath(os.path.dirname(__file__));
rootPath=os.path.split(base_dir);
sys.path.append(base_dir);

# sys.path.append(os.getcwd()+'\\error')

from Base import Error

#词法错误
def lexer_error(token,msg):
    try:
        raise Error(token,msg);
    except Error as e:
        if e.token!='':
            #获取文件路径
            print('[文件] "lexer.py" , line '+str(e.token.lineNumber)+":"+e.token.columnNumber)
            print('词法错误： "'+str(e.token.value)+'" '+e.message+';');
            exit();
        else:
            print('[文件] "lexer.py" , line ')
            print('词法错误： '+e.message+';');
            exit();

#语法错误
def syntax_error(token,msg):
    try:
        raise Error(token,msg);
    except Error as e:
        #获取文件路径
        # print('[文件] "'+__file__+'" , line '+str(e.token.lineNumber))
        # print('语法错误： "'+str(e.token.value)+'" '+e.message+';');
        print('语法错误： "'+str(token.viewTree())+'" '+e.message+';');
        exit();

#类型错误
def type_error(msg):
    try:
        raise Error('',msg);
    except Error as e:
        #获取文件路径
        print('[文件] "'+__file__+'" , line '+0)
        print('类型错误： '+e.message+';');
        exit();

